<style>
    .xxpayPopupDiv .layui-form-label {
        width:120px !important;
        margin-left:1%;
    }
    .xxpayPopupDiv .layui-input-inline {
        width: 80% !important;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <form class="layui-form center">
                    <input type="hidden" name="subMchId" id="subMchId">
                    <div class="layui-form-item">
                        <label class="layui-form-label">限制当天交易金额(元)</label>
                        <div class="layui-input-inline">
                            <input type="text" id="dayAmountLimit" name="dayAmountLimit" placeholder="输入当天交易金额" autocomplete="off" class="layui-input" style="width:200px; display: inline!important;">
                            <i class="layui-icon layui-icon-about"></i> 今日已交易金额： <span id="dayAmountTip"></span>元
                            <p style="color: #cc0000;font-size: xx-small">提示： -1不限制金额</p>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">限制单笔最大金额(元)</label>
                        <div class="layui-input-inline">
                            <input type="text" id="maxEveryAmountLimit" name="maxEveryAmountLimit" placeholder="输入单笔最大金额" autocomplete="off" class="layui-input" style="width:200px; display: inline!important;">
                            <p style="color: #cc0000;font-size: xx-small">提示：-1不限制金额</p>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">风控状态</label>
                        <div class="layui-input-inline" >
                            <input type="radio" name="riskStatus" title="开启" value="1" />
                            <input type="radio" name="riskStatus" title="关闭" value="0" checked="checked" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <button type="button" class="layui-hide xxpayYesBtn" lay-submit="" lay-filter="update">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>

    layui.use(['form','table','util','admin'],function(){
        var form = layui.form
                , $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , element = layui.element
                , view = layui.view;

        element.render('breadcrumb', 'breadcrumb'); //渲染导航信息

        var subMchId = view.getOpenParams('subMchId');
        admin.req({
            type: 'post',
            url: layui.setter.baseUrl + '/config/pay_alizft_mchInfo/get',
            data: {
                subMchId:subMchId,
            },
            error: function(err){
                layer.alert(err);
            },
            success: function(res){
                if(res.code == 0){
                    $('#subMchId').val(res.data.subMchId);

                    $('#dayAmountTip').text(res.data.dayAmount/100);
                    $('#dayAmountLimit').val(res.data.dayAmountLimit==-1?"-1":res.data.dayAmountLimit/100);
                    $('#maxEveryAmountLimit').val(res.data.maxEveryAmountLimit==-1?"-1":res.data.maxEveryAmountLimit/100);
                    if(res.data.riskStatus == 1) {
                        $("input[name='riskStatus'][value='1']").attr("checked",true);
                    }else {
                        $("input[name='riskStatus'][value='0']").attr("checked",true);
                    }
                    form.render();
                }
            }
        });

        form.on('submit(update)', function(data){
            // 验证金额
            var reg = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
            if (data.field.dayAmountLimit != -1 && !reg.test(data.field.dayAmountLimit)) {
                layer.alert("请输入正确的风控当日交易金额");
                return false;
            }
            if (data.field.maxEveryAmountLimit != -1 && !reg.test(data.field.maxEveryAmountLimit)) {
                layer.alert("请输入正确的单笔最大金额");
                return false;
            }

            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/config/pay_alizft_mchInfo/risk_update', //模拟接口,
                data: data.field,
                error: function(err){layer.alert(err.msg,{title:"请求失败"})},
                success: function(res){
                    if(res.code == 0){
                        layer.alert(res.msg, {title: '保存成功'},function(index){
                            layer.closeAll(); //关闭所有弹层
                            layui.table.reload('tableReload'); //调用业务弹层外表格重新加载
                        });
                    }
                }
            })
            return false;
        });

    });

</script>
